<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>src/vfs/extfs/helpers/u7z</title>
<meta name='robots' content='noindex,nofollow' />
<meta name='generator' content='GLOBAL-6.5.7' />
<meta http-equiv='Content-Style-Type' content='text/css' />
<link rel='stylesheet' type='text/css' href='../style.css' />
</head>
<body>
<!-- beginning of fixed guide -->
<div id='guide'><ul>
<li><a href='#TOP'><img class='icon' src='../icons/first.png' alt='[^]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/last.png' alt='[v]' /></a></li>
<li><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a></li>
<li><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a></li>
<li><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a></li>
<li class='standout'><span><a href='../files/src.html'>src</a>/<a href='../files/src--vfs.html'>vfs</a>/<a href='../files/src--vfs--extfs.html'>extfs</a>/<a href='../files/src--vfs--extfs--helpers.html'>helpers</a>/u7z</span></li>
</ul></div>
<!-- end of fixed guide -->
<a id='TOP' name='TOP'></a><h2 class='header'><a href='../mains.html'>root</a>/<a href='../files/src.html'>src</a>/<a href='../files/src--vfs.html'>vfs</a>/<a href='../files/src--vfs--extfs.html'>extfs</a>/<a href='../files/src--vfs--extfs--helpers.html'>helpers</a>/u7z</h2>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><img class='icon' src='../icons/n_top.png' alt='[top]' /><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+1 src/vfs/extfs/helpers/u7z'  /> */</em>
<hr />
<pre>
<a id='L1' name='L1'></a>#! /bin/sh
<a id='L2' name='L2'></a>#
<a id='L3' name='L3'></a># extfs support for p7zip
<a id='L4' name='L4'></a># Written by Pavel Roskin &lt;proski@gnu.org&gt;
<a id='L5' name='L5'></a># Some Bugfixes/workarounds by Sergiy Niskorodov &lt;sgh@mail.zp.ua&gt;
<a id='L6' name='L6'></a>#
<a id='L7' name='L7'></a># This program is free software: you can redistribute it and/or modify
<a id='L8' name='L8'></a># it under the terms of the GNU General Public License as published by
<a id='L9' name='L9'></a># the Free Software Foundation, either version 3 of the License, or
<a id='L10' name='L10'></a># (at your option) any later version.
<a id='L11' name='L11'></a>#
<a id='L12' name='L12'></a># This program is distributed in the hope that it will be useful,
<a id='L13' name='L13'></a># but WITHOUT ANY WARRANTY; without even the implied warranty of
<a id='L14' name='L14'></a># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<a id='L15' name='L15'></a># GNU General Public License for more details.
<a id='L16' name='L16'></a>#
<a id='L17' name='L17'></a># You should have received a copy of the GNU General Public License
<a id='L18' name='L18'></a># along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
<a id='L19' name='L19'></a> 
<a id='L20' name='L20'></a>P7ZIP=`which 7z 2&gt;/dev/null` || P7ZIP=`which 7za 2&gt;/dev/null` || P7ZIP=`which 7zr 2&gt;/dev/null` || P7ZIP=""
<a id='L21' name='L21'></a> 
<a id='L22' name='L22'></a># Let the test framework hook in:
<a id='L23' name='L23'></a>P7ZIP=${MC_TEST_EXTFS_LIST_CMD:-$P7ZIP}
<a id='L24' name='L24'></a>STAT=${MC_TEST_EXTFS_U7Z_STAT:-stat}
<a id='L25' name='L25'></a> 
<a id='L26' name='L26'></a>mcu7zip_list ()
<a id='L27' name='L27'></a>{
<a id='L28' name='L28'></a>        # Symlinks are not shown - no idea how to distinguish them
<a id='L29' name='L29'></a>        # Read-only files are not shown as such - it's rarely useful
<a id='L30' name='L30'></a> 
<a id='L31' name='L31'></a>        ugid="`id -nu` `id -ng`"
<a id='L32' name='L32'></a> 
<a id='L33' name='L33'></a>        date_re='^\(....\)-\(..\)-\(..\) \(..:..:..\)' # 19 chars.
<a id='L34' name='L34'></a>        date_mc='\2-\3-\1 \4'
<a id='L35' name='L35'></a>        empty_date_re='^ \{19\}'
<a id='L36' name='L36'></a> 
<a id='L37' name='L37'></a>        size_re='............' # 12 chars.
<a id='L38' name='L38'></a>        empty_size_re=' \{12\}'
<a id='L39' name='L39'></a>        zero_size='           0'
<a id='L40' name='L40'></a> 
<a id='L41' name='L41'></a>        # archive entries can have no datetime info, 7z will use archive file datetime
<a id='L42' name='L42'></a>        date_archive=`$STAT -c %y "$1" 2&gt;/dev/null | sed -n "s/${date_re}.*/${date_mc}/p" 2&gt;/dev/null`
<a id='L43' name='L43'></a>        [ "${date_archive}"x = x ] &amp;&amp; date_archive=`ls -lan "$1" 2&gt;/dev/null | awk '{print $6, $7, $8}' 2&gt;/dev/null`
<a id='L44' name='L44'></a>        [ "${date_archive}"x = x ] &amp;&amp; date_archive="01-01-1970 00:00:00"
<a id='L45' name='L45'></a> 
<a id='L46' name='L46'></a>        $P7ZIP l "$1" | sed -n "
<a id='L47' name='L47'></a> 
<a id='L48' name='L48'></a>                  # If the uncompressed size is missing, we copy the compressed size onto it.
<a id='L49' name='L49'></a>                  #
<a id='L50' name='L50'></a>                  # But first, if the compressed size is missing too, set it to zero:
<a id='L51' name='L51'></a>                  s/^\(.\{19\} [D.]....\) $empty_size_re $empty_size_re/\1 $zero_size $zero_size/
<a id='L52' name='L52'></a>                  # Next, do the copy:
<a id='L53' name='L53'></a>                  s/^\(.\{19\} [D.]....\) $empty_size_re \($size_re\)/\1 \2 \2/
<a id='L54' name='L54'></a>                  #
<a id='L55' name='L55'></a>                  # (We use '.\{19\}' as the date may be missing. It may give false positives
<a id='L56' name='L56'></a>                  # but we don't mind: the printing commands that follow use strict patterns.).
<a id='L57' name='L57'></a> 
<a id='L58' name='L58'></a>                  # Handle directories.
<a id='L59' name='L59'></a>                  s/$date_re D.... $size_re $size_re\(.*\)/drwxr-xr-x 1 $ugid 0 $date_mc \5/p
<a id='L60' name='L60'></a>            s/$empty_date_re D.... $size_re $size_re\(.*\)/drwxr-xr-x 1 $ugid 0 $date_archive \1/p
<a id='L61' name='L61'></a> 
<a id='L62' name='L62'></a>                  # Handle normal files.
<a id='L63' name='L63'></a>                  s/$date_re \..... \($size_re\) $size_re\(.*\)/-rw-r--r-- 1 $ugid \5 $date_mc \6/p
<a id='L64' name='L64'></a>            s/$empty_date_re \..... \($size_re\) $size_re\(.*\)/-rw-r--r-- 1 $ugid \1 $date_archive \2/p
<a id='L65' name='L65'></a>        "
<a id='L66' name='L66'></a>}
<a id='L67' name='L67'></a> 
<a id='L68' name='L68'></a>mcu7zip_copyout ()
<a id='L69' name='L69'></a>{
<a id='L70' name='L70'></a>        #first we check if we have old p7zip archive with prefix ./ in filename
<a id='L71' name='L71'></a>        $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" &amp;&amp; \
<a id='L72' name='L72'></a>        EXFNAME='*./'"$2" || EXFNAME="$2"
<a id='L73' name='L73'></a>        $P7ZIP e -so "$1" "$EXFNAME" &gt; "$3" 2&gt;/dev/null
<a id='L74' name='L74'></a>}
<a id='L75' name='L75'></a> 
<a id='L76' name='L76'></a>mcu7zip_copyin ()
<a id='L77' name='L77'></a>{
<a id='L78' name='L78'></a>        $P7ZIP a -si"$2" "$1" &lt;"$3" &gt;/dev/null 2&gt;&amp;1
<a id='L79' name='L79'></a>}
<a id='L80' name='L80'></a> 
<a id='L81' name='L81'></a>mcu7zip_mkdir ()
<a id='L82' name='L82'></a>{
<a id='L83' name='L83'></a>        dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-u7z.XXXXXX"` || exit 1
<a id='L84' name='L84'></a>        mkdir -p "$dir"/"$2"
<a id='L85' name='L85'></a>        $P7ZIP a -w"$dir" "$1" "$dir"/"$2" &gt;/dev/null 2&gt;&amp;1
<a id='L86' name='L86'></a>        rm -rf "$dir"
<a id='L87' name='L87'></a>}
<a id='L88' name='L88'></a> 
<a id='L89' name='L89'></a>mcu7zip_rm ()
<a id='L90' name='L90'></a>{
<a id='L91' name='L91'></a>        # NOTE: Version 4.20 fails to delete files in subdirectories
<a id='L92' name='L92'></a>        #first we check if we have old p7zip archive with prefix ./ in filename
<a id='L93' name='L93'></a>        $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" &amp;&amp; \
<a id='L94' name='L94'></a>        EXFNAME='*./'"$2" || EXFNAME="$2"
<a id='L95' name='L95'></a>        $P7ZIP d "$1" "$EXFNAME" 2&gt;&amp;1 | grep -q E_NOTIMPL &gt; /dev/null 2&gt;&amp;1 &amp;&amp; \
<a id='L96' name='L96'></a>        { printf "Function not implemented...\n7z cannot delete from solid archive." &gt;&amp;2 ; exit 1 ; }
<a id='L97' name='L97'></a>}
<a id='L98' name='L98'></a> 
<a id='L99' name='L99'></a>mcu7zip_rmdir ()
<a id='L100' name='L100'></a>{
<a id='L101' name='L101'></a>        #first we check if we have old p7zip archive with prefix ./ in filename
<a id='L102' name='L102'></a>        $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" &amp;&amp; \
<a id='L103' name='L103'></a>        EXFNAME='*./'"$2" || EXFNAME="$2"
<a id='L104' name='L104'></a>        $P7ZIP d "$1" "$EXFNAME"/ 2&gt;&amp;1 | grep -q E_NOTIMPL &gt; /dev/null 2&gt;&amp;1 &amp;&amp; \
<a id='L105' name='L105'></a>        { printf "Function not implemented...\n7z cannot delete from solid archive." &gt;&amp;2 ; exit 1 ; }
<a id='L106' name='L106'></a>}
<a id='L107' name='L107'></a> 
<a id='L108' name='L108'></a># override any locale for dates
<a id='L109' name='L109'></a>LC_DATE=C
<a id='L110' name='L110'></a>export LC_DATE
<a id='L111' name='L111'></a> 
<a id='L112' name='L112'></a>umask 077
<a id='L113' name='L113'></a> 
<a id='L114' name='L114'></a>if [ -z "$P7ZIP" ]; then
<a id='L115' name='L115'></a>    echo "Error: could not find p7zip (looked for 7z, 7za and 7zr)" &gt;&amp;2
<a id='L116' name='L116'></a>    exit 1
<a id='L117' name='L117'></a>fi
<a id='L118' name='L118'></a> 
<a id='L119' name='L119'></a>cmd="$1"
<a id='L120' name='L120'></a>shift
<a id='L121' name='L121'></a> 
<a id='L122' name='L122'></a>case "$cmd" in
<a id='L123' name='L123'></a>  list)    mcu7zip_list    "$@" | sort -k 8 ;;
<a id='L124' name='L124'></a>  copyout) mcu7zip_copyout "$@" ;;
<a id='L125' name='L125'></a>  copyin)  mcu7zip_copyin  "$@" ;;
<a id='L126' name='L126'></a>  mkdir)   mcu7zip_mkdir   "$@" ;;
<a id='L127' name='L127'></a>  rm)      mcu7zip_rm      "$@" ;;
<a id='L128' name='L128'></a>  rmdir)   mcu7zip_rmdir   "$@" ;;
<a id='L129' name='L129'></a>  *) exit 1 ;;
<a id='L130' name='L130'></a>esac
<a id='L131' name='L131'></a>exit 0
</pre>
<hr />
<a id='BOTTOM' name='BOTTOM'></a>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a><img class='icon' src='../icons/n_bottom.png' alt='[bottom]' /><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+131 src/vfs/extfs/helpers/u7z'  /> */</em>
</body>
</html>
